package com.kuaifawu.lwnlawyerclient.Lib;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;

import com.kuaifawu.lwnlawyerclient.R;
import com.kuaifawu.lwnlawyerclient.Activity.LWNLoginActivity;
import com.kuaifawu.lwnlawyerclient.Model.LWNModel_user;

import java.util.Timer;
import java.util.TimerTask;


/**
 * Created by zhangminglei on 15/1/7.
 */

public class KFWTools {
    /**
     * @param @token失效
     * @return
     */
    public static void tokenInvalid(final Activity activity_self) {
        ToastView_custom toast = new ToastView_custom(activity_self);
        toast.showCustom(activity_self, activity_self.getResources().getString(R.string.tokenInvalid));

        TimerTask task = new TimerTask() {
            public void run() {
                Intent intent = new Intent();
                intent.setClass(activity_self, LWNLoginActivity.class);
                activity_self.startActivityForResult(intent, 300);
                activity_self.finish();
                LWNModel_user.getInstance().loginOut(activity_self);
            }
        };
        Timer timer = new Timer();
        timer.schedule(task, 1000);
    }


    /**
     * @param @检测sim卡
     * @return
     */
    public static Boolean getSimState(Context context) {
        TelephonyManager telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        int simState = telMgr.getSimState();
        if (simState == TelephonyManager.SIM_STATE_READY) {
            return true;
        } else if (simState == TelephonyManager.SIM_STATE_ABSENT) {
            return false;
        } else {
            return false;
        }
    }

    /**
     * @return SD卡是否存在
     */
    public static boolean getSDCard() {
        if (android.os.Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED)) {
            return true;
        } else
            return false;
    }

    /**
     * @return 获取适配尺寸
     */
    public static float getFixSize(Activity activity) {
        DisplayMetrics dm = new DisplayMetrics();
        dm = activity.getResources().getDisplayMetrics();
        return dm.widthPixels/dm.density;
    }
}
